<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
	
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品添加页面</title>

<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.4.4.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/messages_cn.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.form.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.validate.method.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${BasePath}/res/js/product/commodityCat.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/json2.js"></script>
<style type="text/css">
    body{ font-size:12px;}
    .l-table-edit {}
    .l-table-edit-td{ padding:4px;}
    .l-button-submit,.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
    .l-verify-tip{ left:230px; top:120px;}
    .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
	.p-tab .s-lab{font-size:12px;font-family:"微软雅黑",​"宋体",​Arial,​sans-serif;}
	input.l-textarea{width:170px;height:20px;font-size:12px;}
	
	.errorcss{border-color:red;}
	
	.table-cell {
	    padding: 4;
	    margin: 0;
	    overflow: hidden;
	    border: 1px solid #b5cbf7;
	    text-align: center;
	}
	.table-cell .l-grid-hd-cell {
	    padding: 4;
	    margin: 0;
	    overflow: hidden;
	    border: 1px solid #b5cbf7;
	    text-align: center;
	}
</style>
</head>


<body style="padding:10px">
<div class="navbar">
		<span>您当前的位置：</span>
		商品管理 &gt; 商品列表 &gt; 修改商品
</div>
<form name="form1" action="update_commo.do" method="post" id="form1">
<input type="hidden" id="catNo" name="catNo" value="${catNo }">
<input type="hidden" id="commoNo" name="commoNo" value="${commodityVo.commoNo }">
<input type="hidden" id="productString" name="productString" >
<input type="hidden" id="delProdNo" name="delProdNo" />


<table cellpadding="0" cellspacing="0" class="l-table-edit p-tab"  style="font-size: 12px;">
	<tr>
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font> 商品分类：</td>
        <td align="left" class="l-table-edit-td s-lab">
        	<div id="catDiv"></div>
        </td>
        <td align="left"></td>
    </tr>
    
    <tr>
        <td align="right" class="l-table-edit-td s-lab"><font  color="red">*</font>商品名称：</td>
        <td align="left" class="l-table-edit-td "><input value="${commodityVo.commoName}" name="commoName" type="text" id="commoName" class="l-textarea"  validate="{required:true,rangelength:[1,30]}" /></td>
        <td align="left"></td>
    </tr>
	
     <tr>
        <td align="right" class="l-table-edit-td s-lab" ><font color="red">*</font>商品类型：</td>
        <td align="left" class="l-table-edit-td s-lab"> 
        <input type="radio" name="commoType" value="0" <c:if test="${commodityVo.commoType == 0}">checked="true"</c:if> />商品
        <%-- <input type="radio" name="commoType" value="1" <c:if test="${commodityVo.commoType == 1}">checked="true"</c:if> />赠品
		<input type="radio" name="commoType" value="2" <c:if test="${commodityVo.commoType == 2}">checked="true"</c:if> />免费货 --%>
		<input type="radio" name="commoType" value="3" <c:if test="${commodityVo.commoType == 3}">checked="true"</c:if> />虚拟商品
        </td><td align="left"></td>
    </tr>
    
     <tr>
        <td align="right" class="l-table-edit-td s-lab" ><font color="red">*</font>品牌：</td>
     	 <td align="left" class="l-table-edit-td s-lab"> 
     	 <select name="brandNo" id="brandNo"></select>
        </td>
        <td align="left"></td>
    </tr>
    	
    <tr>
        <td align="right" class="l-table-edit-td s-lab">商品描述：</td>
        <td align="left" class="l-table-edit-td"><textarea class="l-textarea" style="width: 800px;height: 100px;" rows="10" cols="50" name="description" onkeyup="this.value=this.value.substring(0,2000);"  validate="{required:false,rangelength:[1,2000]}">${commodityVo.description}</textarea>
        </td><td align="left"></td>
    </tr>
	</table>
	<br />
	
		<div><font color="red">*</font>请选择货品规格:</div>
		<div id="choosespecDiv" style="margin-top: 10px;">
		</div>
		<br />	
		
	<div style="margin-top:15px;"><input type="button" onclick="addProdRow()" value="添加货品"></div>
	<br>
	
	
	<div style="width:100%;height:300px;overflow :scroll ">
		<table id="productTable" class="l-grid-header-table"    style=" background: #e0edff; font-size: 12px;"  width="100%" class = "l-panel">
			<tr class="l-grid-hd-row">
				<th class="table-cell">货品条码</th>
				<th class="table-cell">销售类型</th>
				<th class="table-cell">库存类型</th>
				<th class="table-cell">含税零售价</th>
				<th class="table-cell">税率(%)</th>
				<th class="table-cell">未税零售价</th>
				<th class="table-cell">最低订货数量</th>
				<th class="table-cell">箱包装规格</td>
				<th class="table-cell">单位</td>
				<th style="width:70px" class="table-cell"><div style="width: 50px;">操作</div></th>
			</tr>
			<c:forEach var="item" items="${prolist}">
				<tr class="table-cell">
					<td class='l-grid-hd-cell'>
						<input type="hidden" value="${item.prodNo }" name='prodNo' id="prodNo"  />
						<input type='text' value="${item.prodBarCode }" name='prodBarCode' onchange='specification(this);validationProdBarCode(this);checkRepeatProdBarCode(this)' maxlength="14" size="14">
					</td>
					<td class='l-grid-hd-cell'>
						<select name='saleType'  onchange='specification(this)' id="saleType0">
							<!-- <option value=''>请选择</option> -->
							<option value='1' <c:if test="${item.saleType == 1}">selected="selected"</c:if>>购销</option>
							<%-- <option value='2' <c:if test="${item.saleType == 2}">selected="selected"</c:if>>代销</option> --%>
						</select>
					</td>
					<td class='l-grid-hd-cell'>
						<select name='inventoryType'  onchange='specification(this)'>
							<!-- <option value=''>请选择</option> -->
							 <c:choose>
							 <c:when test="${item.inventoryType == 1}">
							   <option value='1' <c:if test="${item.inventoryType == 1}">selected="selected"</c:if>>实库</option>
							 </c:when>
							   <c:when test="${item.inventoryType == 2}">
							 <option value='2' <c:if test="${item.inventoryType == 2}">selected="selected"</c:if>>虚库</option>
							</c:when>
							</c:choose>
						</select>
					</td>
					
					<td class='l-grid-hd-cell'>
						<input type='text' value="${item.salePrice }" name='salePrice' maxlength="11" onchange='specification(this);validationIsNumber(this);calcUnSalPrice(this)' size='11' >
					</td>
					<td class='l-grid-hd-cell'>
						<input type='text' value="${item.prodRate }" name='prodRate' maxlength="5"  onchange='specification(this);validationRateIsNumber(this);calcUnSalPrice(this)' size='5'>
					</td>
					<td class='l-grid-hd-cell'>
						<input type='text' value="${item.unSalePrice }" name='unSalePrice' maxlength="11"  onchange='specification(this);validationIsNumber(this)' size='11'>
					</td>
				
					<td class='l-grid-hd-cell'>
						<input type='text' value="${item.buyNum }" name='buyNum' maxlength="10"  onchange='specification(this);validationIsNumber(this);validationBuyNum(this)' size='10'>
					</td>
					<td class='l-grid-hd-cell'>
						<input type='text' value="${item.casePakgSize }" name='casePakgSize' maxlength="15"  onchange='specification(this)' size='15'>
					</td>
					<td class='l-grid-hd-cell'>
						<input type='text' value="${item.prodUnit }" name='prodUnit' maxlength="15" onchange='specification(this)' size='15'>
					</td>
					<td>
						<a href='#' onclick="javascript:delProdRow(this,'${item.prodNo }');">删除</a>
					</td>
				</tr>
			</c:forEach>
		</table>
	</div>

<input type="submit" value="保存" id="submit1" class="l-button l-button-submit" /> 
<input type="button" value="取消" name="tests" id="tests" class="l-button l-button-test" />
</form>	
</table>
<script type="text/javascript">
	var basePath="${BasePath}";
	var grid = null;
	var i=1;
	
	
	 var commoType=$("#form1").find("input[name=commoType]:checked").val();
	 var inventoryType=1;
	 $("#form1").find("input[name=commoType]").change(function(){
		 if($(this).val()==3){
			 inventoryType=2;
		 }else{
			 inventoryType=1
		 }
		 $("select[name=inventoryType]").html("");
		 $("select[name=inventoryType]").each(function(){
			 if(inventoryType==1){
			 	$(this).append("<option value='1'>实库</option>");
			 }else{
				 $(this).append("<option value='2'>虚库</option>");
			 }			 
		 });
	 }); 
	 if(commoType==3){
		 inventoryType=2
	 }
	//添加某一货品录入模版
	function addProdRow(){
		var str = "";
		for ( var le = 0; le < checkcol.length; le++) {
			str += checkcol[le];
		}
	    
		var inventoryCell="";
		if(inventoryType==1){
			inventoryCell="<td class='l-grid-hd-cell'><select name='inventoryType' onchange='specification(this)' class='errorcss' ><option value='1'>实库</option></select></td>";
		}else{
			inventoryCell="<td class='l-grid-hd-cell'><select name='inventoryType' onchange='specification(this)' class='errorcss' ><option value='2'>虚库</option></select></td>";			
		}
		
		var tr = "<tr><td class='table-cell'><input type='hidden' name='prodNo' id='prodN' /><input type='text' name='prodBarCode' maxlength='14' onchange='specification(this);validationProdBarCode(this);checkRepeatProdBarCode(this)'  class='errorcss' size='20'></td>"
			+str
			+ "<td class='l-grid-hd-cell'><select name='saleType'  onchange='specification(this)' class='errorcss'><option value=''>请选择</option><option value='1'>购销</option><option value='2'>代销</option></select></td>"
			//+ "<td class='l-grid-hd-cell'><select name='inventoryType' onchange='specification(this)' class='errorcss' ><option value=''>请选择</option><option value='1'>实库</option><option value='2'>虚库</option></select></td>"
			+ inventoryCell 
			+ "<td class='l-grid-hd-cell'><input type='text' name='salePrice' maxlength='11' onchange='specification(this);validationIsNumber(this);calcUnSalPrice(this)' size='11' class='errorcss'></td>"
			+ "<td class='l-grid-hd-cell'><input type='text' name='prodRate' maxlength='5' onchange='specification(this);validationRateIsNumber(this);calcUnSalPrice(this)' size='5' class='errorcss'></td>"
			+ "<td class='l-grid-hd-cell'><input type='text' name='unSalePrice' maxlength='11' onchange='specification(this);validationIsNumber(this)' size='11' class='errorcss'></td>"
			+ "<td class='l-grid-hd-cell'><input type='text' name='buyNum' maxlength='10' onchange='specification(this);validationIsNumber(this);validationBuyNum(this)' size='10' class='errorcss'></td>"
			+ "<td class='l-grid-hd-cell'><input type='text' name='casePakgSize' maxlength='15'  onchange='specification(this)'  size='15' class='errorcss'></td>"
			+ "<td class='l-grid-hd-cell'><input type='text' name='prodUnit' maxlength='15' onchange='specification(this)' size='15'></td>"
			+ "<td class='l-grid-hd-cell'><a href='#' onclick='javascript:delProdRow(this);'>删除</a></td>"
			+ "</tr>";
			
			$("#productTable").append(tr);
			i++;
	}
	
	//是否为空的提示
	function specification(obj){
		
		$.each($("select[name=inventoryType],[name=saleType]"),function(i){
			if($(this).toString().match($(obj).toString()) != null){
				var saleType = $("select[name=saleType]").eq(i).val();
				var inventoryType = $("select[name=inventoryType]").eq(i).val();
				if(saleType == '1' && inventoryType == 2){
					$("select[name=inventoryType]").eq(i).val("1");
				}
			}
		});
		
		$(obj).removeClass("errorcss");
		if(obj.value=='' && obj.name!='prodUnit'){
			$(obj).addClass("errorcss");
		}
	}
	
	var delProdNo = new Array();
	//删除某一货品录入模版
	function delProdRow(obj,prodNo){
		if($("#productTable tr").length < 3){
			$.ligerDialog.warn("一个商品至少有一件货品");
			return false;
		}
		if(prodNo != null || prodNo != "") delProdNo.push({"prodNo":prodNo});
		$(obj.parentElement.parentElement).remove();
	}
	
	//分类
	$(function() {
		//初始加载分类
		readonlyCat('${commodityVo.catNo}');
	});

	
	$(function() {
		//分类显示对应的品牌
		$("#brandNo").empty();// 清空下来框
        $("#brandNo").append("<option value='0'>请选择品牌</option>");
		
		$.post('${BasePath}/product/commoditymgt/get_brand_list.do', {
			catNo : '${commodityVo.catNo}'
		}, 
		function(data) {
			if(data != ""){
				var obj=$.parseJSON(data);
				for(var i in obj){
					if(obj[i].brandNo == '${commodityVo.brandNo}'){
						var option = "<option selected='selected' value='"+obj[i].brandNo +"'>"+obj[i].brandName+"</option>";
	                    $("#brandNo").append(option);
					}else{
						var option = "<option value='"+obj[i].brandNo +"'>"+obj[i].brandName+"</option>";
	                    $("#brandNo").append(option);
					}
					
				 };
			}
		});
		//分类显示对应的品牌结束
	});
	
	//初始化显示规格
	$(function() {
		//分类显示对应的规格
		var productList=[];
		//初始化货品
		$.post('${BasePath}/product/commoditymgt/getProductVos.do', {
			commoNo : "${commodityVo.commoNo }"
		}, 
		function(data) {
			productList = $.parseJSON(data);
		});
		var specValue = null;
		if(productList != null){
			if(productList[0].specification != null){
				specValue = productList[0].specification.split(",");
			}
		}
		
		$.post('${BasePath}/product/specmgt/getSpecificationListByCatNo.do', {
			catNo : '${commodityVo.catNo}'
		}, 
		function(data) {
			if(data != ""){
				var obj=$.parseJSON(data);
				var Specification = "";
				for(var i in obj){
					var st =  "<input type='checkbox' name='"+obj[i].specName+"' value='"+obj[i].specNo+"' onclick='choosekbox(this)' />";
					for ( var j in specValue) {
						if(specValue[j].split("-")[0] == obj[i].specNo){
							st =  "<input checked='checked' type='checkbox' name='"+obj[i].specName+"' value='"+obj[i].specNo+"' onclick='choosekbox(this)' />";
							var spec = new Array();
							spec.name= obj[i].specName;
							spec.value= obj[i].specNo;
							addSpecification(spec,productList);
						}
					}
					Specification += st +obj[i].specName;
				};
				$("#choosespecDiv").append(Specification);
			};
		});
		//分类显示对应的规格结束
	});
	
	var checkcol = [];
	var proName = [];
	//动态加载规格值
	function choosekbox(spec) {
		//选择规格
		if (spec.checked) {
			var selectoptions = "";
			$.post('${BasePath}/product/specmgt/getSpecificationListBySpecNo.do', {
				specNo : spec.value
			}, 
			function(data) {
				if(data != ""){
					var obj=$.parseJSON(data);
					obj = obj.specValOptions;
					for(var i in obj){
						
						selectoptions += "<option value='"+obj[i].optionNo+"'>" + obj[i].optionName + "</option>";
					};
				};
			});
			
			var newth = "<th name='"+spec.value+"'>" + spec.name + "</th>";
			var newtd = "<td name='"+spec.value+"'><select name='"+ spec.value + "'>" + selectoptions + "</select></td>";
			
			$(".productth2 ").before(newth);
			$(".producttable2 ").before(newtd);
			checkcol[checkcol.length] = newtd;
			proName[proName.length] = spec.value;
		} else {
			$("th").remove("[name="+spec.value+"]");
			$("td").remove("[name="+spec.value+"]");
			for ( var i = 0; i < proName.length; i++) {
				if (proName[i] == spec.value) {
					checkcol.splice(i, 1);
					proName.splice(i, 1);
				}
			}
		}
		//选择规格结束
	};
	
	
	//初始化加载规格值
	function addSpecification(spec,productList) {
		var selectoptions2 = "";
		$.post('${BasePath}/product/specmgt/getSpecificationListBySpecNo.do', {
			specNo : spec.value
		}, 
		function(data) {
			if(data != ""){
				var obj=$.parseJSON(data);
				obj = obj.specValOptions;
				var newth = "<th name='"+spec.value+"'>" + spec.name + "</th>";
				$(".productth2").before(newth);
				var newtd2 = "";
				//遍历货品
				for ( var pi in productList) {
					var selectoptions = "";
					selectoptions2 = "";
					//遍历规格值
					for(var i in obj){
						//货品规格与规格值
						var option = "<option value='"+obj[i].optionNo+"'>" + obj[i].optionName + "</option>";
						selectoptions2 += option;
						var specValue = new String(productList[pi].specification).split(",");
						for ( var si in specValue) {
							if(specValue[si].split("-")[0] == spec.value && specValue[si].split("-")[1] == obj[i].optionNo){
								option = "<option selected='selected' value='"+obj[i].optionNo+"'>" + obj[i].optionName + "</option>";
							} 
						}
						selectoptions += option;
					};
					
					var newtd = "<td name='"+spec.value+"'><select name='"+ spec.value + "'>" + selectoptions + "</select></td>";
					newtd2 = "<td name='"+spec.value+"'><select name='"+ spec.value + "'>" + selectoptions2 + "</select></td>";
					
					$(".producttable2").eq(pi).before(newtd);
					
				};
				checkcol[checkcol.length] = newtd2;
				proName[proName.length] = spec.value;
			};
		});
	};
	
	//验证输入价格的是否是数字
	 function validationIsNumber(obj){
		 var rule = /^[1-9]\d*|[1-9]\d*\.\d*|0\.\d*[1-9]\d*$/;
		 var value = obj.value;
		 if (value!='') {
			 value = parseFloat(value);
			 if(value <= 0){
				 $.ligerDialog.warn("价格必须大于0!");
				 obj.value="";
				 $(obj).removeClass("errorcss");
				 $(obj).addClass("errorcss");
			 }else{
				 obj.value=value;
			 }
		}
	 }
	
	//验证货品条码
	 function validationProdBarCode(obj){
		 var value = obj.value;
		 if (value!='') {
			 if(!/^\w+$/.test(value)){
				 $.ligerDialog.warn("输入的条码不符合条码规范!");
				obj.value = "";
				$(obj).removeClass("errorcss");
				$(obj).addClass("errorcss");
			 }else{
				 obj.value=value;
			 }
		}
	 }
	
	//验证最低订货数量
	 function validationBuyNum(obj){
		 var value = obj.value;
		 if (value!='') {
			 if(!/^[1-9]\d*$/.test(value)){
				 $.ligerDialog.warn("最低订货数量请输入正整数!");
				obj.value = "";
				$(obj).removeClass("errorcss");
				$(obj).addClass("errorcss");
			 }else{
				 obj.value=value;
			 }
		}
	 }
	
	//验证输入的税率
	 function validationRateIsNumber(obj){
		 var value = obj.value;
		 value = parseFloat(value);
		 if(isNaN(value) || 0 >value||value>100){
			 $.ligerDialog.warn("请输入0-100范围内的数字!");
			 obj.value="";
			 $(obj).removeClass("errorcss");
			 $(obj).addClass("errorcss");
		 }
			
	 }
	 
	 //计算未税零售价   说明: 未税零售价=含税零售价/（1+税率）
	 function calcUnSalPrice(obj){
		var i = $("input[name=salePrice]").index($(obj));
		i = i == -1 ? $("input[name=prodRate]").index($(obj)) : i;
		var salePrice = $("input[name=salePrice]").eq(i).val();
		var prodRate = $("input[name=prodRate]").eq(i).val();
		if(salePrice!=""&&prodRate!=""){
			var unSalePrice=Number(salePrice)/Number(1+Number(prodRate)/100);
			var x = 2;
			if(unSalePrice.toString().length > 11) x = 0;
			$("input[name=unSalePrice]").eq(i).val(unSalePrice.toFixed(x));
			if($("input[name=unSalePrice]").eq(i).val()!=''){
				$("input[name=unSalePrice]").eq(i).removeClass("errorcss");
			}
		}
	 }
		
	 
	
	//验证货品条码是否重重复
	function checkRepeatProdBarCode(obj){
		var prodBarCode=obj.value;
		
		var prodBarCodeRepeatCount=0;
		if(prodBarCode!=""){
			$("input[name=prodBarCode]").each(function(i) {
				if(this.value == prodBarCode) prodBarCodeRepeatCount++ ;
				if(prodBarCodeRepeatCount==2){
					$.ligerDialog.warn("输入的货品条码重复，请重新输入");
					obj.value = "";
					$(obj).removeClass("errorcss");
					$(obj).addClass("errorcss");
					return false;
				}
			});
		
		if(prodBarCodeRepeatCount<2||prodBarCodeRepeatCount>2){
			$.post(
					basePath + '/product/commoditymgt/validationRepeatProdBarCode.do',
					{prodBarCode : prodBarCode},
				 	function(data) {
						if(data == "success"){
							$.ligerDialog.warn("该货品条码已存在，请重新输入！");
							obj.value = "";
							$(obj).removeClass("errorcss");
							$(obj).addClass("errorcss");
						};
			});
		}
		}
	}
	
	//from提交
$(function ()
		{
			//validate
		    $.metadata.setType("attr", "validate");
		    var v = $("form").validate({
		        errorPlacement: function (lable, element)
		        {
		        	lable.ligerHideTip();
		            if (element.hasClass("l-textarea"))
		            {
		                element.ligerTip({ content: lable.html(), target: element[0] }); 
		            }
		            else if (element.hasClass("l-text-field"))
		            {
		                element.parent().ligerTip({ content: lable.html(), target: element[0] });
		            }
		            else
		            {
		                lable.appendTo(element.parents("td:first").next("td"));
		            }
		        },
		        success : function(lable) {
					lable.ligerHideTip();
					lable.remove();
				},
		        submitHandler:function()
		        {
		        	if($("#oneLevel").val()=="0"){
		        		$.ligerDialog.warn("请先选择分类!");
		        		$("#oneLevel").focus();
		        		return false;
		        	}
		        	if($("#brandNo").val()=="0"){
		        		$.ligerDialog.warn("请先选择品牌!");
		        		$("#brandNo").focus();
		        		return false;
		        	}
		        	
		        	if($("#productTable tr").length < 2){
		    			$.ligerDialog.warn("一个商品至少有一件货品");
		    			return false;
		    		}
		        	
		        	var jsonstring = [];
		        	var isSpecStr = true;
					if ($("#producttable tr td .errorcss").length > 0) {
						$.ligerDialog.warn("请填写红色标记的不能为空的货品信息!");
						return false;
					}else{
						$("#productTable tr").each(
								function(i) {
									var prodBarCode = $(this).find("td input[name='prodBarCode']").val();
									var saleType= $(this).find("td select[name='saleType']").val();
									var inventoryType= $(this).find("td select[name='inventoryType']").val();
									var salePrice = $(this).find("td input[name='salePrice']").val();
									var unSalePrice = $(this).find("td input[name='unSalePrice']").val();
									var prodRate = $(this).find("td input[name='prodRate']").val();
									var buyNum = $(this).find("td input[name='buyNum']").val();
									var casePakgSize = $(this).find("td input[name='casePakgSize']").val();
									var prodNo = $(this).find("td input[name='prodNo']").val();
									if(prodBarCode != null&&prodBarCode!="") prodBarCode = prodBarCode.replace(" ","");
									var prodUnit = $(this).find("td input[name='prodUnit']").val();
									if(prodNo != "" && saleType == 2){
										$.post( basePath + "/product/commoditymgt/getAjaxPageFinderProdSupplier.do",
												{prodNo:prodNo},
												function(data){
													var obj = $.parseJSON(data);
													if(obj.Total > 1){
														$.ligerDialog.warn("货品"+prodBarCode+" 有多个供应商，销售类型不能为代销");
														isSpecStr = false;
														return false;
													}
										});
									}
									
									var specStr="";
									for ( var d = 0; d < proName.length; d++) {
										var specNo = proName[d];
										var optionNo= $(this).find(	"td select[name='" + specNo+ "']").val();
										var trSpec=specNo+"-"+optionNo;
										specStr+=","+trSpec;
									}
									if(specStr==""){
										$.ligerDialog.warn("请添加货品规格");
										isSpecStr = false;
										return false;
									}
									// 去掉第一个#
									if (specStr.length > 1) {
										specStr = specStr.substring(1, specStr.length);
									}
									if(i>0){
										jsonstring.push({prodBarCode:prodBarCode,prodNo:prodNo,saleType:saleType,inventoryType:inventoryType,salePrice:salePrice,casePakgSize:casePakgSize,specStr:specStr,unSalePrice:unSalePrice,prodRate:prodRate,buyNum:buyNum,prodUnit:prodUnit});
									}
								}
						);
						document.getElementById("productString").value = JSON.stringify(jsonstring);
						//删除货品
						document.getElementById("delProdNo").value = JSON.stringify(delProdNo);
					}
					if(!isSpecStr) return isSpecStr;
					
		            $("form .l-text,.l-textarea").ligerHideTip();
		            var options = {
		            		type: 'POST',
		            		beforeSend: function(){
		            			//$("#form1").find(":submit,:button").attr("disabled", true);
		            		},
		            		success: function(data){
		            			if(data=="success") {
		            				window.parent.f_tip('修改成功');
		            				close_liger_tab();
		            			} else {
		            				window.parent.f_tip('修改失败');
		            			}
		            		}
		            	}, $form1 = $("#form1");
		           $form1.ajaxSubmit(options);
		           return false;
		        }
		    });
		}); 
	
// 取消
$("#tests").click(function() {
	close_liger_tab();
});
</script>
</body>
</html>